package com.example.mapper;

import com.example.entity.MbtiQuestion;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface MbtiQuestionMapper {
    @Select("SELECT * FROM mbti_question")
    List<MbtiQuestion> findAll();

    @Select("SELECT * FROM mbti_question " +
            "WHERE (#{questionText} IS NULL OR question_text LIKE CONCAT('%', #{questionText}, '%')) " +
            "AND (#{dimension} IS NULL OR dimension = #{dimension}) ")
    List<MbtiQuestion> selectPage(MbtiQuestion mbtiQuestion);

    @Insert("insert into mbti_question (question_text, dimension, option_a, option_b) VALUES (#{questionText},#{dimension},#{optionA},#{optionB})")
    void add(MbtiQuestion mbtiQuestion);

    @Update("update mbti_question set question_text=#{questionText},dimension=#{dimension},option_a=#{optionA},option_b=#{optionB} where question_id=#{questionId}")
    void update(MbtiQuestion mbtiQuestion);

    @Delete("delete from mbti_question where question_id=#{questionId}")
    void delete(Integer questionId);
}
